package com.wealth.system.service.impl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.wealth.system.entity.Role;
import com.wealth.system.repository.RoleDao;
import com.wealth.system.repository.UserDao;
import com.wealth.system.service.IRoleService;

import iaas.service.impl.BaseServiceImpl;

/**
 * @author chan
 *
 */
@Component
public class RoleServiceImpl extends BaseServiceImpl<Role> implements IRoleService{

	@Autowired
	private RoleDao roleDao;
	@Autowired
	private UserDao userDao;

	@Override
	public void saveRole(Role role) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void updateRole(Role role) {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public List<Role> getRoleByCorpIdAndStatus(Long corpid,Integer status) throws Exception{
		return roleDao.findByCorpIdAndStatus(corpid, status);
	}

	@Override
	public List<Role> getRoleByCorpIdAndUserIdAndStatus(Long corpid,Long userid,Integer status) throws Exception {
		List<Role> list1 = roleDao.findByCorpIdAndStatus(corpid, status);
		List<Role> list2 = userDao.findOne(userid).getRoleList();
		Set<Role> setList = new HashSet<Role>();
		List<Role> list = new ArrayList<Role>();
		for (Role role : list1) {
			setList.add(role);
		}
		for (Role role : list2) {
			setList.add(role);
		}
		for (Role role : setList) {
			list.add(role);
		}
		return list;
	}

	
	
}
